package com.liuwei.assemble.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author liuwei19
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private boolean success;
    private int code;
    private String message;
    private T data;

    public static Result success(){
        return new Result(true,ResultCode.SUCCESS.getCode(),"success",null);
    }

    public static<T> Result<T> success(T data){
        return new Result(true,ResultCode.SUCCESS.getCode(),"success",data);
    }

    public static Result fail(){
        return new Result(false,ResultCode.SYSTEM_ERROR.getCode(), ResultCode.SYSTEM_ERROR.getMessage(),null);
    }

    public static Result fail(ResultCode codeEnum){
        return new Result(false,codeEnum.getCode(),codeEnum.getMessage(),null);
    }

    public static<T> Result<T> fail(T data){
        return new Result(false,ResultCode.SYSTEM_ERROR.getCode(), ResultCode.SYSTEM_ERROR.getMessage(),data);
    }

    public static Result fail(int code,String message){
        return new Result(false,code,message,null);
    }

    public static Result fail(String message){
        return new Result(false,ResultCode.SYSTEM_ERROR.getCode(),message,null);
    }

    public static<T> Result<T> fail(int code,String message,T data){
        return new Result(false,code,message,data);
    }

}
